export class y3Player {
    static idMap: Map<py.RoleID, y3Player> = new Map()

    handle: py.Role
    id: number


    constructor(pyPlayer: py.Role) {
        this.handle = pyPlayer
        this.id = pyPlayer.get_role_id_num()
    }
    toString() {
        return `{Player|${this.id}}`
    }

    static toPlayer(this: void, id: py.RoleID) {
        return y3Player.getById(id)
    }

    static getByHanlde(this: void, pyPlayer: py.Role) {
        let id = pyPlayer.get_role_id_num();
        let tempPlayer = y3Player.idMap.get(id);
        if (tempPlayer == null) {
            y3Player.idMap.set(id, new y3Player(pyPlayer))
        }
        return y3Player.idMap.get(id) as y3Player
    }

    static getById(this: void, id: py.RoleID) {
        let tempPlayer = y3Player.idMap.get(id);
        if (tempPlayer == null) {
            let pyPlayer = GameAPI.get_role_by_role_id(id)
            return y3Player.getByHanlde(pyPlayer)
        }
        return tempPlayer
    }

}